package com.das.mechanic_alone.mvp.view.alone.utils;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.das.mechanic_base.R;
import com.das.mechanic_base.adapter.alone.X3AloneChoiceAdapter;
import com.das.mechanic_base.bean.alone.AloneChoiceBean;
import com.das.mechanic_base.bean.alone.AloneDeductionBean;
import com.das.mechanic_base.bean.alone.AloneNewBean;
import com.das.mechanic_base.bean.alone.AloneSpinnerView;
import com.das.mechanic_base.def.alone.AloneSubmitStatus;
import com.das.mechanic_base.utils.X3ScreenUtils;
import com.das.mechanic_base.utils.X3StringUtils;
import com.das.mechanic_base.widget.X3MyListView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by chensi on 2018/4/26.
 */

public class X3AloneChangePagerUtils {

    /**
     * 百分比滑竿
     * @param mContext
     * @param viewGroup
     */
    public static View alonePercentSlider (Context mContext,String content,String answer,ViewGroup viewGroup,View v_shape,List<AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean> deductionList) {

        View view = View.inflate(mContext, R.layout.x3_alone_number_percent_title,null);
        viewGroup.addView(view);

        EditText et_number = view.findViewById(R.id.et_number);
        TextView tv_status = view.findViewById(R.id.tv_status);
        TextView tv_percent = view.findViewById(R.id.tv_percent);
        TextView tv_error = view.findViewById(R.id.tv_error);
        ImageView iv_error = view.findViewById(R.id.iv_error);

        LinearLayout.LayoutParams contentParams = (LinearLayout.LayoutParams) view.getLayoutParams();
        contentParams.height = X3ScreenUtils.dipToPx(54,mContext);
        contentParams.topMargin = X3ScreenUtils.dipToPx(16,mContext);
        contentParams.leftMargin = X3ScreenUtils.dipToPx(16,mContext);
        contentParams.rightMargin = X3ScreenUtils.dipToPx(16,mContext);
        view.setLayoutParams(contentParams);

        String numberStatus = "";
        if (!X3StringUtils.isEmpty(content) && X3StringUtils.isAloneNum(content)) {
            tv_percent.setGravity(Gravity.CENTER_VERTICAL);
            et_number.setText(content);
            et_number.setSelection(content.length());
            v_shape.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_process_green));
            numberStatus = X3AloneChangePagerUtils.getPercentNumberStatus(Double.parseDouble(content), deductionList).status;

        }else {
            tv_percent.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
            et_number.setText("");
            v_shape.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_red_shape));
            numberStatus = "";
        }

//        else if (!StringUtils.isEmpty(answer) && StringUtils.isAloneNum(answer)) {
//            tv_percent.setGravity(Gravity.CENTER_VERTICAL);
//            et_number.setText(answer);
//            et_number.setSelection(answer.length());
//            v_shape.setBackground(ContextCompat.getDrawable(mContext,R.drawable.process_green));
//            numberStatus = AloneChangePagerUtils.getPercentNumberStatus(Double.parseDouble(answer), deductionList).status;
//        }

        tv_error.setVisibility(View.GONE);
        iv_error.setVisibility(View.GONE);
        if ("".equals(numberStatus)) {
            et_number.setHint(mContext.getString(R.string.x3_please_input_num));
            tv_percent.setTextColor(ContextCompat.getColor(mContext,R.color.c333));
            tv_status.setVisibility(View.GONE);
        }else {
            et_number.setHint("");
            tv_status.setVisibility(View.VISIBLE);

            if (AloneSubmitStatus.MINOR.equals(numberStatus)) {
                tv_status.setText("（" + mContext.getString(R.string.x3_minor_notice) + "）");
                view.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_alone_number_minor_bg));
                et_number.setTextColor(Color.parseColor("#F3850F"));
                tv_status.setTextColor(Color.parseColor("#F3850F"));
                tv_percent.setTextColor(Color.parseColor("#F3850F"));

            } else if (AloneSubmitStatus.MAJOR.equals(numberStatus)) {
                tv_status.setText("（" + mContext.getString(R.string.x3_major_notice) + "）");
                view.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_alone_number_dangerous_bg));
                et_number.setTextColor(Color.parseColor("#F64458"));
                tv_status.setTextColor(Color.parseColor("#F64458"));
                tv_percent.setTextColor(Color.parseColor("#F64458"));

            } else if (AloneSubmitStatus.DANGEROUS.equals(numberStatus)) {
                tv_status.setText("（" + mContext.getString(R.string.x3_error_notice) + "）");
                view.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_alone_number_dangerous_bg));
                et_number.setTextColor(Color.parseColor("#F64458"));
                tv_status.setTextColor(Color.parseColor("#F64458"));
                tv_percent.setTextColor(Color.parseColor("#F64458"));

            }else if (AloneSubmitStatus.PASS.equals(numberStatus)){
                tv_status.setText("（" + mContext.getString(R.string.x3_normal_notice) + "）");
                view.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_alone_number_normal_bg));
                et_number.setTextColor(Color.parseColor("#18BE6B"));
                tv_status.setTextColor(Color.parseColor("#18BE6B"));
                tv_percent.setTextColor(Color.parseColor("#18BE6B"));

            } else {
                iv_error.setVisibility(View.VISIBLE);
                tv_error.setVisibility(View.VISIBLE);
                tv_status.setText("");
                tv_percent.setTextColor(ContextCompat.getColor(mContext,R.color.c333));
                et_number.setTextColor(ContextCompat.getColor(mContext,R.color.c333));
                view.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_alone_number_error_notice));
            }
        }

        return view;
    }

    /**
     * 轮胎选择器
     * @param mContext
     * @param aloneBean
     * @param viewGroup
     */
    public static void aloneTyreWidget (Context mContext, AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean aloneBean, View viewGroup, List<AloneSpinnerView> spinnerList,String s9,String s10,String s11,String answer,int index,String title) {
        View view = View.inflate(mContext, R.layout.x3_tyre_picker_notice,null);
        TextView tv_one = view.findViewById(R.id.tv_one);
        TextView tv_two = view.findViewById(R.id.tv_two);
        TextView tv_three = view.findViewById(R.id.tv_three);
        View v_one = view.findViewById(R.id.v_one);
        View v_two = view.findViewById(R.id.v_two);
        View v_three = view.findViewById(R.id.v_three);

        LinearLayout.LayoutParams contentParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        contentParams.topMargin = X3ScreenUtils.dipToPx(20,mContext);
        contentParams.leftMargin = X3ScreenUtils.dipToPx(16,mContext);
        view.setLayoutParams(contentParams);

        for (int i = 0; i < 3; i++) {
            if (i == 0) {
                if (s9 != null && !"".equals(s9)) {
                    tv_one.setText(s9+"");
                }else if (answer != null && !"".equals(answer)) {
                    String[] split = answer.split("-");
                    tv_one.setText(split[0]+"");
                }else {
                    tv_one.setText(mContext.getString(R.string.x3_tyre_width));
                }

            }else if (i == 2){
                if (s10 != null && !"".equals(s10)) {
                    tv_two.setText(s10+"");
                }else if (answer != null && !"".equals(answer)) {
                    String[] split = answer.split("-");
                    tv_two.setText(split[1]+"");
                }else {
                    tv_two.setText(mContext.getString(R.string.x3_flat_than));
                }
            }else {
                if (s11 != null && !"".equals(s11)) {
                    tv_three.setText(s11+"");
                }else if (answer != null && !"".equals(answer)) {
                    String[] split = answer.split("-");
                    tv_three.setText(split[2]+"");
                }else {
                    tv_three.setText(mContext.getString(R.string.x3_diameter));
                }
            }
            spinnerList.add(new AloneSpinnerView(view,false,index,title));
        }
        String s = tv_one.getText().toString();
        String s1 = tv_two.getText().toString();
        String s2 = tv_three.getText().toString();
        if ((mContext.getString(R.string.x3_tyre_width)).equals(s)) {
            tv_two.setTextColor(Color.parseColor("#C2CAD2"));
            v_two.setBackgroundColor(Color.parseColor("#C2CAD2"));
        }else {
            tv_one.setTextColor(Color.parseColor("#0077ff"));
            v_one.setBackgroundColor(Color.parseColor("#0077ff"));
        }

        if ((mContext.getString(R.string.x3_flat_than)).equals(s1)) {
            tv_two.setTextColor(Color.parseColor("#C2CAD2"));
            v_two.setBackgroundColor(Color.parseColor("#C2CAD2"));
        }else {
            tv_two.setTextColor(Color.parseColor("#0077ff"));
            v_two.setBackgroundColor(Color.parseColor("#0077ff"));
        }

        if ((mContext.getString(R.string.x3_diameter)).equals(s2)) {
            tv_three.setTextColor(Color.parseColor("#C2CAD2"));
            v_three.setBackgroundColor(Color.parseColor("#C2CAD2"));
        }else {
            tv_three.setTextColor(Color.parseColor("#0077ff"));
            v_three.setBackgroundColor(Color.parseColor("#0077ff"));
        }

        ((LinearLayout) viewGroup).addView(view);
    }

    /**
     * 选择题
     * @param mContext
     * @param aloneBean
     * @param viewGroup
     */
    public static AloneChoiceBean aloneChoice (Context mContext,AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean aloneBean,
                                               View viewGroup,String content,int index) {
        View view = View.inflate(mContext, R.layout.x3_number_picker_notice,null);
        LinearLayout al_tv_container6 = view.findViewById(R.id.al_tv_container);
        al_tv_container6.removeAllViews();
        X3MyListView listView = new X3MyListView(mContext);
        listView.setDivider(null);

        LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams1.leftMargin = X3ScreenUtils.dipToPx(16,mContext);
        layoutParams1.rightMargin = X3ScreenUtils.dipToPx(16,mContext);
        listView.setLayoutParams(layoutParams1);
        X3AloneChoiceAdapter errorAdapter = null;
        if (content != null && !"".equals(content)) {
            errorAdapter = new X3AloneChoiceAdapter(aloneBean.questionCarMilesDeductionEntityList,mContext,content);

        }else {
            errorAdapter = new X3AloneChoiceAdapter(aloneBean.questionCarMilesDeductionEntityList,mContext,"");
        }

        listView.setAdapter(errorAdapter);
        AloneChoiceBean aloneChoiceBean = new AloneChoiceBean(listView, errorAdapter,  index);

        ((LinearLayout)viewGroup).addView(listView);
        return aloneChoiceBean;
    }

    public static View aloneNumber(Context mContext,String content,String answer,ViewGroup viewGroup,View v_shape,List<AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean> deductionList) {
        View view = View.inflate(mContext, R.layout.x3_alone_number_title,null);
        viewGroup.addView(view);

        EditText et_number = view.findViewById(R.id.et_number);
        TextView tv_status = view.findViewById(R.id.tv_status);
        TextView tv_error = view.findViewById(R.id.tv_error);
        ImageView iv_error = view.findViewById(R.id.iv_error);
        ImageView iv_input_r = view.findViewById(R.id.iv_input_r);
        LinearLayout ll_error = view.findViewById(R.id.ll_error);
        RelativeLayout rl_input = view.findViewById(R.id.rl_input);

        LinearLayout.LayoutParams contentParams = (LinearLayout.LayoutParams) view.getLayoutParams();
//        contentParams.height = X3ScreenUtils.dipToPx(48,mContext);
        contentParams.topMargin = X3ScreenUtils.dipToPx(16,mContext);
        contentParams.leftMargin = X3ScreenUtils.dipToPx(16,mContext);
        contentParams.rightMargin = X3ScreenUtils.dipToPx(16,mContext);
        view.setLayoutParams(contentParams);

        String numberStatus = "";
        if (!X3StringUtils.isEmpty(content) && X3StringUtils.isAloneNum(content)) {
            et_number.setText(content);
            et_number.setSelection(content.length());
            v_shape.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_process_green));
            numberStatus = X3AloneChangePagerUtils.getCurrentNumberStatus(Double.parseDouble(content), deductionList).status;

        }else {
            et_number.setText("");
            v_shape.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_red_shape));
            numberStatus = "";
        }

//        else if (!StringUtils.isEmpty(answer) && StringUtils.isAloneNum(answer)) {
//            et_number.setText(answer);
//            et_number.setSelection(answer.length());
//            v_shape.setBackground(ContextCompat.getDrawable(mContext,R.drawable.process_green));
//            numberStatus = AloneChangePagerUtils.getCurrentNumberStatus(Double.parseDouble(answer), deductionList).status;
//        }

        tv_error.setVisibility(View.GONE);
        iv_error.setVisibility(View.GONE);
        if ("".equals(numberStatus)) {
            et_number.setHint(mContext.getString(R.string.x3_please_input_num));
            tv_status.setVisibility(View.GONE);
        }else {
            tv_status.setVisibility(View.VISIBLE);

            if (AloneSubmitStatus.MINOR.equals(numberStatus)) {

                tv_status.setText("（" + mContext.getString(R.string.x3_minor_notice) + "）");
                view.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_alone_number_minor_bg));
                et_number.setTextColor(Color.parseColor("#F3850F"));
                tv_status.setTextColor(Color.parseColor("#F3850F"));
                iv_input_r.setImageResource(R.mipmap.x3_alone_input_warning);
            } else if (AloneSubmitStatus.MAJOR.equals(numberStatus)) {

                tv_status.setText("（" + mContext.getString(R.string.x3_major_notice) + "）");
                view.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_alone_number_dangerous_bg));
                et_number.setTextColor(Color.parseColor("#F64458"));
                tv_status.setTextColor(Color.parseColor("#F64458"));
                iv_input_r.setImageResource(R.mipmap.x3_alone_input_danger);
            } else if (AloneSubmitStatus.DANGEROUS.equals(numberStatus)) {

                tv_status.setText("（" + mContext.getString(R.string.x3_error_notice) + "）");
                view.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_alone_number_dangerous_bg));
                et_number.setTextColor(Color.parseColor("#F64458"));
                tv_status.setTextColor(Color.parseColor("#F64458"));
                iv_input_r.setImageResource(R.mipmap.x3_alone_input_danger);
            }else if (AloneSubmitStatus.PASS.equals(numberStatus)){

                tv_status.setText("（" + mContext.getString(R.string.x3_normal_notice) + "）");
                view.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_alone_number_normal_bg));
                et_number.setTextColor(Color.parseColor("#18BE6B"));
                tv_status.setTextColor(Color.parseColor("#18BE6B"));
                iv_input_r.setImageResource(R.mipmap.x3_alone_input_normal);
            } else {
//                iv_error.setVisibility(View.VISIBLE);
//                tv_error.setVisibility(View.VISIBLE);
                ll_error.setVisibility(View.VISIBLE);

                tv_status.setText("");
                et_number.setTextColor(ContextCompat.getColor(mContext,R.color.c333));
                view.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_alone_number_error_bg2));
//                view.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_alone_number_error_notice));
            }
        }

        return view;
    }

    /**
     * 获取选择题当前选择的状态
     * @param content
     * @param carList
     * @return
     */
    public static AloneDeductionBean getCurrentChoiceStatus(String content, List<AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean> carList) {
        AloneDeductionBean deductionBean = new AloneDeductionBean();

        if (!X3StringUtils.isListEmpty(carList)) {
            for (int choice = 0; choice < carList.size(); choice++) {
                /**
                 * 判断值在哪个区间
                 */
                String optionDescription = carList.get(choice).optionDescription;
                if (X3StringUtils.isEmpty(optionDescription)) {
                    continue;
                }
                if (optionDescription.equals(content)) {

                    deductionBean.id  = carList.get(choice).id;
                    deductionBean.status = carList.get(choice).status;
                    deductionBean.deductionPercentOrAmount = carList.get(choice).deductionPercentOrAmount;
                    deductionBean.deductionType = carList.get(choice).deductionType;
                    break;
                }
            }
        }else {
            deductionBean.status = AloneSubmitStatus.PASS;
        }
        return deductionBean;
    }

    /**
     * 获取选择题当前选择 推荐服务项目
     * @param content
     * @param carList
     * @return
     */
    public static AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean getCurrentChoiceTouchList(String content, List<AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean> carList) {
        List<AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean.TouchCycleBaseServiceEntityListBean> mList = new ArrayList<>();

        AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean afterBean = new AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean();
        if (X3StringUtils.isListEmpty(carList)) {
            return afterBean;
        }

        if (!X3StringUtils.isListEmpty(carList) && !X3StringUtils.isEmpty(content)) {
            for (int choice = 0; choice < carList.size(); choice++) {
                /**
                 * 判断值在哪个区间
                 */
                AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean questionCarMilesDeductionEntityListBean = carList.get(choice);
                String optionDescription = carList.get(choice).optionDescription;
                if (X3StringUtils.isEmpty(optionDescription)) {
                    continue;
                }
                if (optionDescription.equals(content)) {
                    afterBean = carList.get(choice);
                    break;
                }
            }
        }
        return afterBean;
    }

    /**
     * 获取当前数值题 的状态
     * @return
     */
    public static AloneDeductionBean getPercentNumberStatus(double numberAnswer,List<AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean> carList) {
        AloneDeductionBean deductionBean = new AloneDeductionBean();
        if (!X3StringUtils.isListEmpty(carList)) {
            for (int number = 0; number < carList.size(); number++) {
                /**
                 * 判断值在哪个区间
                 */
                String optionDescription = carList.get(number).optionDescription;
                if (X3StringUtils.isEmpty(optionDescription)) {
                    continue;
                }
                if (!optionDescription.contains("~")) {
                    if (!X3StringUtils.isAloneNum(optionDescription)) {
                        continue;
                    }
                    if (numberAnswer != Double.parseDouble(optionDescription)) {
                        continue;
                    }
                    deductionBean.id  = carList.get(number).id;
                    deductionBean.status = carList.get(number).status;
                    deductionBean.deductionPercentOrAmount = carList.get(number).deductionPercentOrAmount;
                    deductionBean.deductionType = carList.get(number).deductionType;
                    break;
                }
                optionDescription = optionDescription.replaceAll("%", "");
                String[] question = optionDescription.split("~");
                if (!X3StringUtils.isEmpty(question[0]) && !X3StringUtils.isEmpty(question[1])) {
                    if (numberAnswer >= Double.parseDouble(question[0]) && numberAnswer < Double.parseDouble(question[1])) {
                        deductionBean.id  = carList.get(number).id;
                        deductionBean.status = carList.get(number).status;
                        deductionBean.deductionPercentOrAmount = carList.get(number).deductionPercentOrAmount;
                        deductionBean.deductionType = carList.get(number).deductionType;
                        break;
                    }else {
                        deductionBean.status = AloneSubmitStatus.ILLEGAL;
                    }
                }else if (!X3StringUtils.isEmpty(question[0]) && X3StringUtils.isEmpty(question[1])) {
                    if (numberAnswer == Double.parseDouble(question[0])) {
                        deductionBean.id  = carList.get(number).id;
                        deductionBean.status = carList.get(number).status;
                        deductionBean.deductionPercentOrAmount = carList.get(number).deductionPercentOrAmount;
                        deductionBean.deductionType = carList.get(number).deductionType;
                        break;
                    }else {
                        deductionBean.status = AloneSubmitStatus.ILLEGAL;
                    }
                }else if (X3StringUtils.isEmpty(question[0]) && !X3StringUtils.isEmpty(question[1])) {
                    if (numberAnswer == Double.parseDouble(question[1])) {
                        deductionBean.id  = carList.get(number).id;
                        deductionBean.status = carList.get(number).status;
                        deductionBean.deductionPercentOrAmount = carList.get(number).deductionPercentOrAmount;
                        deductionBean.deductionType = carList.get(number).deductionType;
                        break;
                    }else {
                        deductionBean.status = AloneSubmitStatus.ILLEGAL;
                    }
                }else {
                    deductionBean.status = AloneSubmitStatus.ILLEGAL;
                }
            }
        }else {
            deductionBean.status = AloneSubmitStatus.ILLEGAL;
        }
        return deductionBean;
    }

    /**
     * 获取当前数值题 推荐服务项目
     * @return
     */
    public static AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean getPercentNumberTouchList(double numberAnswer,List<AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean> carList) {

        AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean afterBean = new AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean();

        if (X3StringUtils.isListEmpty(carList)) {
            return afterBean;
        }
        if (numberAnswer < 0) {
            return afterBean;
        }
        for (int number = 0; number < carList.size(); number++) {
            /**
             * 判断值在哪个区间
             */
            String optionDescription = carList.get(number).optionDescription;
            if (X3StringUtils.isEmpty(optionDescription)) {
                continue;
            }
            if (!optionDescription.contains("~")) {
                if (!X3StringUtils.isAloneNum(optionDescription)) {
                    continue;
                }
                if (numberAnswer != Double.parseDouble(optionDescription)) {
                    continue;
                }
                afterBean = carList.get(number);
                break;
            }
            optionDescription = optionDescription.replaceAll("%", "");
            String[] question = optionDescription.split("~");
            if (!X3StringUtils.isEmpty(question[0]) && !X3StringUtils.isEmpty(question[1])) {
                if (numberAnswer >= Double.parseDouble(question[0]) && numberAnswer < Double.parseDouble(question[1])) {
                    afterBean = carList.get(number);
                    break;
                }
            }else if (!X3StringUtils.isEmpty(question[0]) && X3StringUtils.isEmpty(question[1])) {
                if (numberAnswer == Double.parseDouble(question[0])) {
                    afterBean = carList.get(number);
                    break;
                }
            }else if (X3StringUtils.isEmpty(question[0]) && !X3StringUtils.isEmpty(question[1])) {
                if (numberAnswer == Double.parseDouble(question[1])) {
                    afterBean = carList.get(number);
                    break;
                }
            }
        }
        return afterBean;
    }

    /**
     * 获取当前数值题 的状态
     * @return
     */
    public static AloneDeductionBean getCurrentNumberStatus(double numberAnswer,List<AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean> carList) {

        AloneDeductionBean deductionBean = new AloneDeductionBean();
        if (numberAnswer < 0) {
            return deductionBean;
        }
        if (!X3StringUtils.isListEmpty(carList)) {
            for (int number = 0; number < carList.size(); number++) {
                /**
                 * 判断值在哪个区间
                 */
                String optionDescription = carList.get(number).optionDescription;
                if (X3StringUtils.isEmpty(optionDescription)) {
                    continue;
                }
                if (!optionDescription.contains("~")) {
                    if (!X3StringUtils.isAloneNum(optionDescription)) {
                        continue;
                    }
                    if (numberAnswer != Double.parseDouble(optionDescription)) {
                        continue;
                    }
                    deductionBean.id  = carList.get(number).id;
                    deductionBean.status = carList.get(number).status;
                    deductionBean.deductionPercentOrAmount = carList.get(number).deductionPercentOrAmount;
                    deductionBean.deductionType = carList.get(number).deductionType;
                    break;
                }
                String[] question = optionDescription.split("~");
                if (!X3StringUtils.isEmpty(question[0]) && !X3StringUtils.isEmpty(question[1])) {
                    if (numberAnswer >= Double.parseDouble(question[0]) && numberAnswer < Double.parseDouble(question[1])) {
                        deductionBean.id  = carList.get(number).id;
                        deductionBean.status = carList.get(number).status;
                        deductionBean.deductionPercentOrAmount = carList.get(number).deductionPercentOrAmount;
                        deductionBean.deductionType = carList.get(number).deductionType;
                        break;
                    }else {
                        deductionBean.status = AloneSubmitStatus.ILLEGAL;
                    }
                }else if (!X3StringUtils.isEmpty(question[0]) && X3StringUtils.isEmpty(question[1])) {
                    if (numberAnswer == Double.parseDouble(question[0])) {
                        deductionBean.id  = carList.get(number).id;
                        deductionBean.status = carList.get(number).status;
                        deductionBean.deductionPercentOrAmount = carList.get(number).deductionPercentOrAmount;
                        deductionBean.deductionType = carList.get(number).deductionType;
                        break;
                    }else {
                        deductionBean.status = AloneSubmitStatus.ILLEGAL;
                    }
                }else if (X3StringUtils.isEmpty(question[0]) && !X3StringUtils.isEmpty(question[1])) {
                    if (numberAnswer == Double.parseDouble(question[1])) {
                        deductionBean.id  = carList.get(number).id;
                        deductionBean.status = carList.get(number).status;
                        deductionBean.deductionPercentOrAmount = carList.get(number).deductionPercentOrAmount;
                        deductionBean.deductionType = carList.get(number).deductionType;
                        break;
                    }else {
                        deductionBean.status = AloneSubmitStatus.ILLEGAL;
                    }
                }else {
                    deductionBean.status = AloneSubmitStatus.ILLEGAL;
                }

            }
        }else {
            deductionBean.status = AloneSubmitStatus.ILLEGAL;
        }
        return deductionBean;
    }

    /**
     * 获取当前数值题 推荐服务项目
     * @return
     */
    public static AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean getCurrentNumberTouchList(double numberAnswer,List<AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean> carList) {

        AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean afterBean = new AloneNewBean.ItemQuestionListBean.QuestionDetectionTempletQuestionListBean.QuestionCarMilesDeductionEntityListBean();
        if (X3StringUtils.isListEmpty(carList)) {
            return afterBean;
        }

        for (int number = 0; number < carList.size(); number++) {
            /**
             * 判断值在哪个区间
             */
            String optionDescription = carList.get(number).optionDescription;
            if (X3StringUtils.isEmpty(optionDescription)) {
                continue;
            }
            if (!optionDescription.contains("~")) {
                if (!X3StringUtils.isAloneNum(optionDescription)) {
                    continue;
                }
                if (numberAnswer != Double.parseDouble(optionDescription)) {
                    continue;
                }
                afterBean = carList.get(number);
                break;
            }
            String[] question = optionDescription.split("~");
            if (!X3StringUtils.isEmpty(question[0]) && !X3StringUtils.isEmpty(question[1])) {
                if (numberAnswer >= Double.parseDouble(question[0]) && numberAnswer < Double.parseDouble(question[1])) {
                    afterBean = carList.get(number);
                    break;
                }
            }else if (!X3StringUtils.isEmpty(question[0]) && X3StringUtils.isEmpty(question[1])) {
                if (numberAnswer == Double.parseDouble(question[0])) {
                    afterBean = carList.get(number);
                    break;
                }
            }else if (X3StringUtils.isEmpty(question[0]) && !X3StringUtils.isEmpty(question[1])) {
                if (numberAnswer == Double.parseDouble(question[1])) {
                    afterBean = carList.get(number);
                    break;
                }
            }
        }
        return afterBean;
    }
}
